<template>
  <!-- 主内容区 -->
  <div class="main-content">
    <!-- 功能图片与文字组合 -->
    <div class="function-item fade-in-item">
      <img src="@/assets/user_list.png" alt="用户管理" />
      <p>用户管理</p>
    </div>
    <div class="function-item fade-in-item">
      <img src="@/assets/edit_user.png" alt="编辑用户" />
      <p>编辑用户</p>
    </div>
    <div class="function-item fade-in-item">
      <img src="@/assets/equipment.png" alt="管理设备" style="transform: translateX(10px)" />
      <p>管理设备</p>
    </div>

    <div class="function-item fade-in-item">
      <img src="@/assets/notice.png" alt="通知列表" style="transform: translateX(20px)" />
      <p>通知列表</p>
    </div>
    <div class="function-item fade-in-item">
      <img src="@/assets/new_notice.png" alt="新增通知" />
      <p>新增通知</p>
    </div>

    <div class="function-item fade-in-item">
      <img src="@/assets/user_record.png" alt="人员记录" />
      <p>人员记录</p>
    </div>
    <div class="function-item fade-in-item">
      <img src="@/assets/account.png" alt="账号信息" />
      <p>账号信息</p>
    </div>
    <div class="function-item fade-in-item">
      <img src="@/assets/log.png" alt="操作日志" />
      <p>操作日志</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted } from 'vue'

function handleResize() {
  console.log('窗口宽度变化', nowWidth.value)
}

const nowWidth = computed(() => window.innerWidth)

onMounted(() => {
  // 初始打印一次
  handleResize()
  // 监听窗口大小变化
  window.addEventListener('resize', handleResize)
})

onBeforeUnmount(() => {
  // 移除监听器，防止内存泄漏
  window.removeEventListener('resize', handleResize)
})
</script>

<style scoped>
/* 主内容区样式 - 缩小并向右移动20% */
.main-content {
  padding: 40px 24px;
  background-color: #fff;
  height: calc(100vh - var(--header-height));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 24px;

  @media screen and (max-width: 767px) {
    padding: 20px 8px;
  }
}

/* 功能项基础样式 */
.function-item {
  width: 19.9%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 12px;
  cursor: pointer;
  /* 不要边框把这下面三行删了 */
  /* border: 1px solid #eee; */
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  transition: 0.3s ease; /* 过渡效果 */

  &:hover {
    scale: 1.1;
  }

  @media screen and (max-width: 1023px) {
    width: 24%;
  }

  @media screen and (max-width: 767px) {
    width: 40%;
  }
}

/* 图片基础样式 */
img {
  width: 80%;
  height: auto;
  object-fit: contain;
  margin-bottom: 8px;
  transition: transform 0.3s ease;
}

/* 鼠标悬停时图片放大效果 */
/* img:hover {
  transform: scale(1.1);
} */

/* 文字说明样式 */
.function-item p {
  font-size: 13px;
  color: #333;
  text-align: center;
  margin: 0;
  padding-bottom: 8px;
}

/* 定义浮现动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 给项目添加动画类 */
.fade-in-item {
  opacity: 0;
  animation: fadeIn 0.8s ease forwards;
}

/* 为每个项目设置递增延迟 */
.fade-in-item:nth-child(1) {
  animation-delay: 0s;
}
.fade-in-item:nth-child(2) {
  animation-delay: 0.1s;
}
.fade-in-item:nth-child(3) {
  animation-delay: 0.2s;
}
.fade-in-item:nth-child(4) {
  animation-delay: 0.3s;
}
.fade-in-item:nth-child(5) {
  animation-delay: 0.4s;
}
.fade-in-item:nth-child(6) {
  animation-delay: 0.5s;
}
.fade-in-item:nth-child(7) {
  animation-delay: 0.6s;
}
.fade-in-item:nth-child(8) {
  animation-delay: 0.7s;
}
</style>
